package com.pxst.sys.controller;

import com.pxst.sys.req.IsUseReq;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.pxst.annotations.LogOperate;
import com.pxst.annotations.NoAuthorize;
import com.pxst.resp.ApiResp;
import com.pxst.sys.entity.AuthorityEntity;
import com.pxst.sys.service.AuthorityService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;
import java.util.List;

/** 
* @author yangxy
* @version 创建时间：2023年7月27日 下午4:12:44 
*/
@RestController
@RequestMapping("/sys/authority")
@Api(tags = "权限相关接口")
public class AuthorityConroller {
	@Autowired
	private AuthorityService authorityService;
	
	@NoAuthorize
	@GetMapping("/haveMenu")
	@ApiOperation(value = "获取当前用户所拥有的菜单及按钮权限")
	public ApiResp<AuthorityEntity> getAuthority(){
		return authorityService.getAuthority();
	}


	@NoAuthorize
	@PostMapping("/addAuth")
	@LogOperate(operate = "添加权限", service = AuthorityService.class, type = "add")
	@ApiOperation(value = "添加权限")
	public ApiResp<String> addAuthority(@RequestBody @Valid AuthorityEntity authority){
		return authorityService.addAuthority(authority);
	}

	@NoAuthorize
	@GetMapping("/allAuth")
	@ApiOperation(value = "获取系统所有菜单、按钮权限")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "mode", value = "0：查询未启用，1：查询已启用，2：查询全部", required = true)
	})
	public ApiResp<List<AuthorityEntity>> getAllAuthority(Integer mode) {
		return authorityService.getAllAuthority(mode);
	}

	@NoAuthorize
	@PostMapping("/is_use")
	@LogOperate(operate = "修改权限的启用状态", service = AuthorityService.class, type = "edit")
	@ApiOperation(value = "修改权限的启用状态")
	public ApiResp<String> changeIsUse(@RequestBody IsUseReq isUseReq){
		return authorityService.changeIsUse(isUseReq);
	}

	@NoAuthorize
	@PostMapping("/update_auth")
	@LogOperate(operate = "修改权限内容", service = AuthorityService.class, type = "edit")
	@ApiOperation(value = "修改权限内容")
	public ApiResp<String> updateAuthority(@RequestBody AuthorityEntity authority){
		return authorityService.updateAuthority(authority);
	}

	@NoAuthorize
	@PostMapping("/delAuth")
	@LogOperate(operate = "删除权限", service = AuthorityService.class, type = "del")
	@ApiOperation(value = "删除权限")
	public ApiResp<String> deleteAuthority(Long id){
		return authorityService.deleteAuthority(id);
	}

}
